<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Payment\PaymentScene;

class CreatePaymentScenesTable extends Migration
{

    const TABLE = PaymentScene::TABLE;

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        !Schema::hasTable(self::TABLE) &&
        Schema::create(self::TABLE, function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('parking_lot_id')->index();
            $table->string('name', 50)->default('');
            $table->string('source', 50)->default('')->comment('支付端类型');
            $table->uuid('channel_id')->default('')->comment('支付通道ID');
            $table->unsignedInteger('sequence')->default(0)->comment('排序');
            $table->timestamps();
            $table->unique(['parking_lot_id', 'name', 'source','channel_id'],'uni_idx_scene');
        });
        DB::statement("alter table `".self::TABLE."` comment '支付场景';");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists(self::TABLE);
    }
}
